home *** CD-ROM | disk | FTP | other *** search
- package horst;
-
- import java.awt.AWTEvent;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Cursor;
- import java.awt.Dimension;
- import java.awt.Frame;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Window;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.JComponent;
- import javax.swing.JPanel;
- import javax.swing.UIManager;
-
- public class FrameSplitterBar extends JPanel implements MouseListener {
- static final int SPLITTER_WIDTH = 3;
- private int m_orientation = 0;
- private Window m_newPositionBar;
- private boolean m_bResizable = true;
- private int m_size = 3;
-
- public FrameSplitterBar(int orientation) {
- this.m_orientation = orientation;
- ((JComponent)this).setBackground(UIManager.getColor("control"));
- ((Component)this).setCursor(Cursor.getPredefinedCursor(11));
- ((Component)this).enableEvents(48L);
- ((Component)this).addMouseListener(this);
- }
-
- public int getBarSize() {
- return this.m_size;
- }
-
- Window getTraceWindow() {
- if (this.m_newPositionBar == null) {
- Component c = this;
-
- while(!((c = c.getParent()) instanceof Frame)) {
- }
-
- if (c != null) {
- this.m_newPositionBar = new Window((Frame)c);
- } else {
- this.m_newPositionBar = new Window(new Frame());
- }
-
- this.m_newPositionBar.setBackground(Color.yellow);
- }
-
- return this.m_newPositionBar;
- }
-
- public void mouseClicked(MouseEvent e) {
- }
-
- public void mouseEntered(MouseEvent e) {
- if (this.m_bResizable) {
- if (this.m_orientation == 0) {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(11));
- } else {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(8));
- }
-
- }
- }
-
- public void mouseExited(MouseEvent e) {
- }
-
- public void mousePressed(MouseEvent e) {
- }
-
- public void mouseReleased(MouseEvent evt) {
- if (this.m_bResizable) {
- if (this.m_newPositionBar != null) {
- FrameSplitterBar topBar = null;
- FrameSplitterBar leftBar = null;
- FrameSplitterBar rightBar = null;
- FrameSplitterBar bottomBar = null;
- Rectangle splitterBounds = ((Component)this).getBounds();
- Container parent = ((Component)this).getParent();
- Dimension parentDim = ((Component)parent).getSize();
- Insets parentInsets = parent.getInsets();
- Point parentPos = ((Component)parent).getLocationOnScreen();
- if (parent instanceof FrameSetPanel) {
- leftBar = ((FrameSetPanel)parent).getLeftSplitBar(this);
- rightBar = ((FrameSetPanel)parent).getRightSplitBar(this);
- topBar = leftBar;
- bottomBar = rightBar;
- }
-
- int yPos;
- int xPos;
- if (this.m_orientation == 0) {
- xPos = ((Component)this).getLocationOnScreen().x + evt.getX();
- if (leftBar != null) {
- Point leftPt = ((Component)leftBar).getLocationOnScreen();
- if (xPos <= leftPt.x + 3) {
- xPos = leftPt.x + 3 + 1;
- }
- }
-
- if (rightBar != null) {
- Point rightPt = ((Component)rightBar).getLocationOnScreen();
- if (xPos >= rightPt.x) {
- xPos = rightPt.x - 3;
- }
- }
-
- if (xPos < parentPos.x + parentInsets.left) {
- xPos = parentPos.x + parentInsets.left;
- } else if (xPos > parentPos.x + parentDim.width - splitterBounds.width) {
- xPos = parentPos.x + parentDim.width - splitterBounds.width;
- }
-
- xPos -= parentPos.x;
- yPos = ((Component)this).getBounds().y;
- } else {
- yPos = ((Component)this).getLocationOnScreen().y + evt.getY();
- if (topBar != null) {
- Point topPt = ((Component)topBar).getLocationOnScreen();
- if (yPos <= topPt.y + 3) {
- yPos = topPt.y + 3 + 1;
- }
- }
-
- if (bottomBar != null) {
- Point bottomPt = ((Component)bottomBar).getLocationOnScreen();
- if (yPos >= bottomPt.y) {
- yPos = bottomPt.y - 3;
- }
- }
-
- if (yPos < parentPos.y + parentInsets.top) {
- yPos = parentPos.y + parentInsets.top;
- } else if (yPos > parentPos.y + parentDim.height - splitterBounds.height) {
- yPos = parentPos.y + parentDim.height - splitterBounds.height;
- }
-
- yPos -= parentPos.y;
- xPos = ((Component)this).getBounds().x;
- }
-
- ((Component)this).setBounds(xPos, yPos, splitterBounds.width, splitterBounds.height);
- ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
- this.m_newPositionBar.dispose();
- this.m_newPositionBar = null;
- ((Container)this).invalidate();
- parent.invalidate();
- parent.validate();
- }
-
- }
- }
-
- protected void processMouseMotionEvent(MouseEvent evt) {
- super.processMouseEvent(evt);
- if (this.m_bResizable) {
- Rectangle splitterBounds = ((Component)this).getBounds();
- Container parent = ((Component)this).getParent();
- Dimension parentDim = ((Component)parent).getSize();
- Insets parentInsets = parent.getInsets();
- Point parentPos = ((Component)parent).getLocationOnScreen();
- FrameSplitterBar leftBar = null;
- FrameSplitterBar rightBar = null;
- FrameSplitterBar topBar = null;
- FrameSplitterBar bottomBar = null;
- if (parent instanceof FrameSetPanel) {
- leftBar = ((FrameSetPanel)parent).getLeftSplitBar(this);
- rightBar = ((FrameSetPanel)parent).getRightSplitBar(this);
- topBar = leftBar;
- bottomBar = rightBar;
- }
-
- if (((AWTEvent)evt).getID() == 506) {
- Window w = this.getTraceWindow();
- if (this.m_orientation == 0) {
- int xPos = ((Component)this).getLocationOnScreen().x + evt.getX();
- int yPos = ((Component)this).getLocationOnScreen().y;
- if (leftBar != null) {
- Point leftPt = ((Component)leftBar).getLocationOnScreen();
- if (xPos <= leftPt.x + 3) {
- xPos = leftPt.x + 3;
- }
- }
-
- if (rightBar != null) {
- Point rightPt = ((Component)rightBar).getLocationOnScreen();
- if (xPos >= rightPt.x) {
- xPos = rightPt.x - 3;
- }
- }
-
- if (xPos < parentPos.x + parentInsets.left) {
- xPos = parentPos.x + parentInsets.left;
- } else if (xPos > parentPos.x + parentDim.width - splitterBounds.width) {
- xPos = parentPos.x + parentDim.width - splitterBounds.width;
- }
-
- ((Component)w).setBounds(xPos, yPos, splitterBounds.width, splitterBounds.height);
- } else {
- int xPos = ((Component)this).getLocationOnScreen().x;
- int yPos = ((Component)this).getLocationOnScreen().y + evt.getY();
- if (topBar != null) {
- Point topPt = ((Component)topBar).getLocationOnScreen();
- if (yPos <= topPt.y + 3) {
- yPos = topPt.y + 3 + 1;
- }
- }
-
- if (bottomBar != null) {
- Point bottomPt = ((Component)bottomBar).getLocationOnScreen();
- if (yPos >= bottomPt.y) {
- yPos = bottomPt.y - 3;
- }
- }
-
- if (yPos < parentPos.y + parentInsets.top) {
- yPos = parentPos.y + parentInsets.top;
- } else if (yPos > parentPos.y + parentDim.height - 3) {
- yPos = parentPos.y + parentDim.height - 3;
- }
-
- System.out.println("mousemove yPos =" + yPos);
- ((Component)w).setBounds(xPos, yPos, parentDim.width, 3);
- }
-
- if (!((Component)w).isVisible()) {
- ((Component)w).setVisible(true);
- }
- }
-
- }
- }
-
- public void setBarSize(int sz) {
- this.m_size = sz;
- }
-
- void setOrientation(int orientation) {
- this.m_orientation = orientation;
- }
-
- void setResizable(boolean bResizable) {
- this.m_bResizable = bResizable;
- if (this.m_bResizable) {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(11));
- } else {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
- }
-
- }
-
- void setSize(int width) {
- this.m_size = width;
- }
- }
-